package com.klun.designMode.proxy.myProxy;

import com.klun.designMode.proxy.JDKProxy.Jack;
import com.klun.designMode.proxy.JDKProxy.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 自定义一个代理
 */
public class ZdyMeiPo implements InvocationHandler {
    private Person person;

    //获取被代理人的资料
    public Object getInstance(Person target) throws Exception {
        this.person = target;
        Class zz = target.getClass();
        return ZdyPorxy.newProxyInstance(new ZdyClassLoader(), zz.getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("进入invoke");
        method.invoke(this.person, args);

        System.out.println("方法反射执行完成");
        return null;
    }
}